// 卡片市场
import request from '@/utils/request'

export const api = {
  getbusinessTree: '/business-type/businessType',
  getbusinessTreeAll: '/business-type/typeAll',
  getSearchType: '/business-type/likeType',
  getListAll: '/business-card/listAll',
  downloadAndPreview: '/business-attachment/down',
  updateDetail: '/business-card/updateBy',
  getPlayLog: '/business-card/thirdparty',
  getCardTypeTree: '/business-type/tree',
  getCardDetail: '/business-card/getByTypeId',
  uploadFile: '/business-attachment/up',
  uploadFileMore: '/business-attachment/ups',
  getMenuById: '/business-card/getMenuById',
  getCardListByPage: '/business-config',
  setPortalCardConfig: '/business-config',
  sendFile: '/business-attachment/source-up'
}

// 侧边栏查询接口全部
export function getbusinessTreeAll (params = {}) {
  return request({
    url: api.getbusinessTreeAll,
    method: 'get',
    params
  })
}

// 侧边栏分层级查询接口
export function getbusinessTree (params = {}) {
  return request({
    url: api.getbusinessTree,
    method: 'get',
    params
  })
}

// 侧边栏模糊查询接口
export function getSearchType (params = {}) {
  return request({
    url: api.getSearchType,
    method: 'get',
    params
  })
}

// 查询卡列表
export function getListAll (data = {}) {
  return request({
    url: api.getListAll,
    method: 'post',
    data
  })
}

// 下载/预览
export function downloadAndPreview (params = {}) {
  return request({
    url: api.downloadAndPreview,
    method: 'get',
    responseType: 'blob',
    params
  })
}

// 获取详情
export function getCardDetail (params = {}) {
  return request({
    url: api.getCardDetail,
    method: 'get',
    params
  })
}

// 修改详情 启用禁用卡状态
export function updateDetail (data = {}) {
  return request({
    url: api.updateDetail,
    method: 'post',
    data
  })
}

// 查询操作记录
export function getPlayLog (id) {
  return request({
    url: `${api.getPlayLog}/${id}`,
    method: 'get'
  })
}

// 查询卡片分类树
export function getCardTypeTree () {
  return request({
    url: api.getCardTypeTree,
    method: 'get'
  })
}

// 分页查询卡片列表
export function getCardListByPage (params) {
  return request({
    url: api.getCardListByPage,
    method: 'get',
    params
  })
}

// 上传单个文件
export function uploadFile (data = {}) {
  return request({
    url: api.uploadFile,
    method: 'post',
    data
  })
}

// 上传多个文件
export function uploadFileMore (data = {}) {
  return request({
    url: api.uploadFileMore,
    method: 'post',
    data
  })
}

// 查询卡片是否绑定门户的接口
export function getMenuById (params = {}) {
  return request({
    url: api.getMenuById,
    method: 'get',
    params
  })
}

// 保存个人门户卡片配置
export function setPortalCardConfig (id, menuId, userCards = []) {
  return request({
    url: api.setPortalCardConfig,
    method: 'post',
    data: { id, menuId, userCards }
  })
}

// 获取个人门户卡片配置
export function getCardLayoutConfig (id, menuId) {
  return request({
    url: api.setPortalCardConfig + `/${id}`,
    method: 'get',
    params: { id, menuId }
  })
}

export function sendFile (data = {}) {
  return request({
    url: api.sendFile,
    method: 'POST',
    data
  })
}
